package edu.msg.jthr.backend.repository.beans;

import javax.ejb.Stateless;
import javax.persistence.Query;

import edu.msg.jthr.backend.model.User;
import edu.msg.jthr.backend.repository.RepositoryException;
import edu.msg.jthr.backend.repository.UserRepository;

@Stateless(name = "UserRepository")
public class UserRepositoryBean extends BaseRepositoryBean<User, Integer>
		implements UserRepository {

	// private static final Logger LOG = LoggerFactory
	// .getLogger(BaseRepository.class);

	public UserRepositoryBean() {
		super(User.class);
	}

	@Override
	public User getByName(String name) throws RepositoryException {
		try {
			Query query = getEntityManager()
					.createNamedQuery("User.findByName");
			query.setParameter("username", name);
			User temp = (User) query.getResultList().get(0);
			// LOG.info("GetByName succeded");
			return temp;
		} catch (Exception e) {
			// LOG.error("GetByName failed - repository", e);
			throw new RepositoryException("GetByName failed - repository", e);
		}
	}
}